<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Common\Repositories;

use xsl\utils\Tree;

/**
 * Class BaseRepository.
 */
class BaseRepository
{
    protected $dao;

    public function __call($name, $arguments)
    {
        return call_user_func_array([$this->dao, $name], $arguments);
    }

    public function setDao($dao)
    {
        $this->dao = $dao;
    }



    /**
     * tree 结构
     *
     * @param int $pid
     * @param string $pidField
     * @param string $children
     * @return array
     */
    public function toTree(object $data, int $pid = 0, string $pidField = 'parent_id', string $children = 'children'): array
    {
        $pk = $this->dao->getPk();
        return Tree::setPk($pk)->done($data->toArray(), $pid, $pidField, $children);
    }
}
